package com.demo.simulation;

/**
 * 模拟springboot tomcat容器对filter和servlet的处理逻辑
 */
public class Run {
    public static void main(String[] args) {
        MyApplicationFilterChain myApplicationFilterChain = new MyApplicationFilterChain();
        //自定义filter1
        MyFilterConfig myFilterConfig1 = new MyFilterConfig(new MyFilter() {
            @Override
            public void doFilter(Object request, Object response, MyFilterChain filterChain) {
                System.out.println("进入myFilterConfig1");
                filterChain.doFilter(request, response);
                System.out.println("退出myFilterConfig1");
            }
        });
        //自定义filter2
        MyFilterConfig myFilterConfig2 = new MyFilterConfig(new MyFilter() {
            @Override
            public void doFilter(Object request, Object response, MyFilterChain filterChain) {
                System.out.println("进入myFilterConfig2");
                filterChain.doFilter(request, response);
                System.out.println("退出myFilterConfig2");
            }
        });

        MyFilterConfig[] myFilterConfigs = {myFilterConfig1,myFilterConfig2};
        myApplicationFilterChain.setMyFilterConfigs(myFilterConfigs);

        //自定义servlet
        myApplicationFilterChain.setServlet(new MyServlet() {
            @Override
            public void service(Object req, Object res) {
                System.out.println("执行servlet相关逻辑");
            }
        });

        myApplicationFilterChain.doFilter("request", "respone");

    }
}
